package com.example.informationEntry.service.impl;

import com.example.informationEntry.dao.NaTuitionFeeScheduleDao;
import com.example.informationEntry.entity.NaTuitionFeeSchedule;
import com.example.informationEntry.service.NaTuitionFeeScheduleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 学费信息表(NaTuitionFeeSchedule)表服务实现类
 *
 * @author makejava
 * @since 2019-04-08 11:20:34
 */
@Service("naTuitionFeeScheduleService")
public class NaTuitionFeeScheduleServiceImpl implements NaTuitionFeeScheduleService {
    @Resource
    private NaTuitionFeeScheduleDao naTuitionFeeScheduleDao;

    /**
     * 通过ID查询单条数据
     *
     * @param tuitionInfNumber 主键
     * @return 实例对象
     */
    @Override
    public NaTuitionFeeSchedule queryById(String tuitionInfNumber) {
        return this.naTuitionFeeScheduleDao.queryById(tuitionInfNumber);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<NaTuitionFeeSchedule> queryAllByLimit(int offset, int limit) {
        return this.naTuitionFeeScheduleDao.queryAllByLimit(offset, limit);
    }

    /**
     * 查询多条数据
     *
     * @param naTuitionFeeSchedule 实例对象
     * @return list集合
     */
    @Override
    public List<NaTuitionFeeSchedule> queryAll(NaTuitionFeeSchedule naTuitionFeeSchedule){
        return this.naTuitionFeeScheduleDao.queryAll(naTuitionFeeSchedule);
    }

    /**
     * 新增数据
     *
     * @param naTuitionFeeSchedule 实例对象
     * @return 实例对象
     */
    @Override
    public NaTuitionFeeSchedule insert(NaTuitionFeeSchedule naTuitionFeeSchedule) {
        this.naTuitionFeeScheduleDao.insert(naTuitionFeeSchedule);
        return naTuitionFeeSchedule;
    }

    /**
     * 修改数据
     *
     * @param naTuitionFeeSchedule 实例对象
     * @return 实例对象
     */
    @Override
    public NaTuitionFeeSchedule update(NaTuitionFeeSchedule naTuitionFeeSchedule) {
        this.naTuitionFeeScheduleDao.update(naTuitionFeeSchedule);
        return this.queryById(naTuitionFeeSchedule.getTuitionInfNumber());
    }

    /**
     * 通过主键删除数据
     *
     * @param tuitionInfNumber 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String tuitionInfNumber) {
        return this.naTuitionFeeScheduleDao.deleteById(tuitionInfNumber) > 0;
    }

    @Override
    public Map<String, String> queryTuitionFeeInf(){
        List<NaTuitionFeeSchedule> list = this.naTuitionFeeScheduleDao.queryAll(new NaTuitionFeeSchedule());
        Map<String,String> resultMap = new HashMap<>();
        for (NaTuitionFeeSchedule schedule : list) {
            resultMap.put(schedule.getTuitionInfNumber(),String.valueOf(schedule.getTuitionAmount()));
        }
        return resultMap;
    }
}